package org.boot.easyapi.util.web;

import org.boot.easyapi.expand.AuthenticationUserInfoAbstractInterface;
import org.boot.easyapi.pojo.auto.AuthenticationUserInfo;
import org.boot.easyapi.util.spring.SpringUtil;

/**
 * 当前认证用户工具类
 */
public class AuthenticationUtil {

    /**
     * 获取认证用户信息
     *
     * @return 认证用户信息
     */
    public static AuthenticationUserInfo getAuthenticationUserInfo() {
        return authenticationUserInfo();
    }

    /**
     * 获取认证用户token
     *
     * @return 认证用户token
     */
    public static String getAccessToken() {
        return authenticationUserInfo().getAccessToken();
    }

    /**
     * 获取认证用户刷新token
     *
     * @return 认证用户刷新token
     */
    public static String getRefreshToken() {
        return authenticationUserInfo().getRefreshToken();
    }

    /**
     * 获取认证用户租户ID
     *
     * @return 认证用户租户ID
     */
    public static String getTenantId() {
        return authenticationUserInfo().getTenantId();
    }

    private static AuthenticationUserInfo authenticationUserInfo(){
        AuthenticationUserInfoAbstractInterface abstractInterface = SpringUtil.getBean(AuthenticationUserInfoAbstractInterface.class);
        if (abstractInterface != null) return abstractInterface.getAuthenticationUserInfo();
        return new AuthenticationUserInfo();
    };

}
